<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :edit="edit" :checkedit="checkedit" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {
		buildSubFormData,
		subOnLoad,
		changeEditor,
		configSelectData
	} from '../../../static/js/formUtil.js';
	import {
		ignoreHtml,
		ptFloat,
		minusF,
		getDateStr
	} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				year:'',
				userId:'',
				posId:'',
				exists:'',
				editId:'',
				indexCacheKey:'obj-zb-tindexAdjust-title_before_index-cache'
			})
		},
		methods:{
			setList(id,busRange){
				let _that = this
				_that.om.request(
					"tindexAdjust/setList",
					{
						year: _that.year,
						userId: _that.userId,
						posId: _that.posId,
						indexId: id,
						busRange:busRange
					}
				).then(res=>{
					Object.assign(_that.$refs.autoform.formdata, res.value.list1[0])
				})
			},
			changeType(){
				let _that = this
				for(let index = 0; index<12;index++){
					if(index+1 > month){
						_that.$refs.autoform.changeEditor("title_before","month"+(index+1)+"Name","suffix",_that.$refs.autoform.formdata.indexUnitName)
						_that.$refs.autoform.changeEditor("title_before","month"+(index+1)+"Name","suffixCol",_that.$refs.autoform.formdata.indexUnitName.length)
					}
				}
			},
			initload(){
				let _that = this
			},
		},
		onLoad(e) {
			let _that = this
			_that.year = e.year
			_that.userId = e.userId
			_that.posId = e.posId
			_that.editId = e.editId
			subOnLoad(_that, e, function() {
				_that.exists = _that.datas.filter((e,i)=>{
					return (i != _that.index)
				}).map(e=>e.indexId).join(",")
				if (e.configDataCacheKey) {
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if (res.data && res.data instanceof Array) {
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
							}
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor('title_before',"indexId",{
								link:'../../public/pageSearch/pageSearch',
								"linkParam":{
									other: JSON.stringify({
										year: _that.year,
										userId: _that.userId,
										posId: _that.posId,
										notInStr: _that.exists,
										editId: _that.editId
									}),
									initload: true,
									method:'POST',
									namefield:'indexName',
									notefield:'orderNumStr',
									searchfield:'q',
									url:'tindexAdjust/getIndexList',
									cachename: _that.indexCacheKey,
								}
							},null,_that.autoformdata)
						}
					})
				}
			})
		},
		onShow() {
			let _that = this
			if (_that.$refs.autoform) {
				uni.getStorage({
					key:_that.indexCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							_that.setList(d.indexId,d.busRange)
							uni.removeStorage({
								key:_that.indexCacheKey
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>
